package com.zkthink.ceres.tenant.dao;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.zkthink.base.mapper.SuperMapper;
import com.zkthink.ceres.tenant.dto.TenantApplyAuditDTO;
import com.zkthink.ceres.tenant.entity.TenantApply;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 商家入驻
 * </p>
 *
 * @author vivi.huang
 * @date 2020-06-28
 */
@Repository
public interface TenantApplyMapper extends SuperMapper<TenantApply> {

    /**
     * 平台商家入驻分页总数
     * @param merchantName 商家名称
     * @param headMobile 负责人手机号码
     * @param organizationType 申请主体类型
     * @param applyTimeStart 查询的申请开始时间
     * @param applyTimeEnd 查询的申请结束时间
     * @return
     */
    @SqlParser(filter = true)
    Integer getTotalOfTenantApplyPage(@Param("merchantName") String merchantName,
                                      @Param("headMobile")String headMobile,
                                      @Param("organizationType")String organizationType,
                                      @Param("applyTimeStart")String applyTimeStart,
                                      @Param("applyTimeEnd")String applyTimeEnd,
                                      @Param("auditState")Integer auditState
    );

    /**
     * 平台商家入驻分页列表
     * @param merchantName 商家名称
     * @param headMobile 负责人手机号码
     * @param organizationType 申请主体类型
     * @param applyTimeStart 查询的申请开始时间
     * @param applyTimeEnd 查询的申请结束时间
     * @param page
     * @param size
     * @return
     */
    @SqlParser(filter = true)
    List<TenantApply> findTenantApplyPage(
            @Param("merchantName") String merchantName,
            @Param("headMobile")String headMobile,
            @Param("organizationType")String organizationType,
            @Param("applyTimeStart")String applyTimeStart,
            @Param("applyTimeEnd")String applyTimeEnd ,
            @Param("auditState")Integer auditState,
            @Param("page")long page,
            @Param("size")long size);

    /**
     * 查询
     * @param id
     * @return
     */
    @SqlParser(filter = true)
    TenantApply getTenantApply(@Param("id") Long id);

    /**
     * 审核
     * @param id
     * @param auditTime
     * @param auditState
     * @param rejectReason
     * @param effectDateType
     * @param effectTime
     * @param effectTimeLimit
     */
    @SqlParser(filter = true)
    void auditTenantApply(@Param("id") Long id,
                          @Param("auditTime") String auditTime,
                          @Param("auditState") Integer auditState,
                          @Param("rejectReason") String rejectReason,
                          @Param("effectDateType") Integer effectDateType,
                          @Param("effectTime") String effectTime,
                          @Param("effectTimeLimit") Integer effectTimeLimit,
                          @Param("tenantCode") String tenantCode
    );

    /**
     * 根据号码查找商家
     * @param mobile 注册电话/负责人电话
     * @return
     */
    @SqlParser(filter = true)
    TenantApplyAuditDTO getTenantApplyByHeadMobile(@Param("mobile") String mobile);

    /**
     * 保存
     * @param tenantApply
     * @return
     */
    @SqlParser(filter = true)
    boolean saveTenantApply(TenantApply tenantApply);
}
